package com.zmn.oms.third.jingdong.service;

import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.common.constant.OrderLogConsts;
import com.zmn.oms.model.entity.work.OrderWorkLogChange;
import com.zmn.oms.third.jingdong.JingdongConsts;
import com.zmn.oms.zmn.business.interfaces.open.OrderChangeNotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 类描述：向京东服务+推送订单变化通知的服务
 *
 * @author LiangHailong
 * @date 2019/09/07 16:03
 */
@Slf4j
@Service("jingdongOrderChangeNotifyService")
public class JingdongOrderChangeNotifyServiceImpl implements OrderChangeNotifyService {

    @Autowired
    private JingdongServiceImpl jingdongService;

    @Override
    public void notifyChange(OrderWorkLogChange orderWorkLogChange) {
        if (!JingdongConsts.POWER_ON) {
            log.info("【{}】<订单状态同步> 该功能没有开启。", JingdongConsts.CHANNEL_NAME);
            return;
        }

        int logType = orderWorkLogChange.getLogType().intValue();

        // 修改预约时间
        if (isChangeDutyTime(logType, orderWorkLogChange)) {
            jingdongService.syncDutyTime(orderWorkLogChange);
        }
        // 派单
        else if (OrderLogConsts.ORDER_LOG_TYPE_DISTRIBUTE == logType) {
            jingdongService.syncMaster(orderWorkLogChange);
            jingdongService.syncDutyTime(orderWorkLogChange);
        }
        // 取消、失败、弃单
        else if (OrderLogConsts.ORDER_LOG_TYPE_CANCEL == logType || OrderConsts.ORDER_OP_TYPE_FAIL == logType
                || OrderConsts.ORDER_OP_TYPE_DISCARD == logType) {
            jingdongService.syncOrderCancel(orderWorkLogChange);
        }
        // 完成
        else if (OrderLogConsts.ORDER_LOG_TYPE_COMPLETE == logType) {
            jingdongService.syncOrderComplete(orderWorkLogChange);
        }
    }
}
